$(function() {
	//share
	var shareUrl = $("#share_url").html();
	var sharePic = $("#share_pic").attr("data-src");
	var shareTxt = $("#share_desc").html();
	var shareTitle = $("#share_title").html();
	nie.use(["nie.util.shareV5"], function() {
		var share = nie.util.share({
			fat: "#NIE-share",
			title: shareTitle,
			img: sharePic,
			content: shareTxt,
			url: shareUrl
		});
	});
	
	//视频页
	$video = $('#Jvideo'),
    $video_con = $('#Jvideo .m-video-con'),
    $popbg = $('#mask');
    
    var showPop = function(ele){
        ele.show();
        setTimeout(function(){
            ele.addClass('show');
        },10)
    }
    
    var closePop = function(ele){
        ele.removeClass('show').hide();
        if(ele.attr('id') == 'Jvideo'){
            $video_con.html('');
        }
    }
    
    $video.find('.m-close').bind('click',function(){
        closePop($video)
        closePop($popbg);
    });
	
	//滚动动画
	var s = skrollr.init({
	    smoothScrolling: true,
	    smoothScrollingDuration:500
	});
	
	$(window).on('scroll',function(){
		var scrollTop = $(this).scrollTop();
		$("#navigation li").removeClass("cur");
		if(scrollTop>=0 && scrollTop<877){
			$("#navigation li").eq(0).addClass("cur");
		}
		if(scrollTop>=877 && scrollTop<1727){
			$("#navigation li").eq(1).addClass("cur");
		}
		if(scrollTop>=1727 && scrollTop<2577){
			$("#navigation li").eq(2).addClass("cur");
		}
		if(scrollTop>=2577 && scrollTop<4277){
			$("#navigation li").eq(3).addClass("cur");
		}
		if(scrollTop>=4277){
			$("#navigation li").eq(4).addClass("cur");
		}
	});
	
	$("#navigation li").click(function(){
		var index = $(this).index();
		var scrollTop;
		if(index==4){
			scrollTop = 977+index*850;
		}else if(index==5){
			scrollTop = 0;
		}else{
			scrollTop = 977+(index-1)*850;
		}
		$("html,body").animate({scrollTop: scrollTop},500);
	});
	
	//tabs
	$(".tabs a").click(function(){
		var isActive = $(this).hasClass("active");
		var index = $(this).index()+1;
		if(isActive){
			return;
		}
		$(this).addClass("active");
		$(this).siblings().removeClass("active");
		$("#section-4 .content").hide();
		$("#section-4 .content-"+index).show();
	});
	
	//swiper
	mySwiper = $('.swiper-container').swiper({
		
	});
	
	$('.prev').click(function(){
		mySwiper.swipePrev(); 
	});
	
	$('.next').click(function(){
		mySwiper.swipeNext(); 
	});
	
	$(".content-1 img").click(function(){
		var index = $(this).index();
		$(".tab-1").removeClass("active");
		$(".tab-2").addClass("active");
		$(".content-1").hide();
		$(".content-2").show();
		mySwiper.swipeTo(index);
	});
	
	var initSize = function(){
		var winWidth = $("#wrap").width();
		if(winWidth>=1200 && winWidth<1366){
			$(".prev").addClass("fixed");
			$(".next").addClass("fixed");
			$(".prev").removeClass("fixed2");
			$(".next").removeClass("fixed2");
		}else if(winWidth>=1366 && winWidth<1660){
			$(".prev").addClass("fixed2");
			$(".next").addClass("fixed2");
			$(".prev").removeClass("fixed");
			$(".next").removeClass("fixed");
		}else{
			$(".prev").removeClass("fixed fixed2");
			$(".next").removeClass("fixed fixed2");
		}
	}
	
	initSize();
	
	$(window).resize(function(){
		initSize();
	});
	
	//关闭弹窗
	$('.dialog-close').on('click',function(){
        closePop($dialog)
        closePop($popbg);
        if(document.addEventListener){ 
			document.addEventListener('DOMMouseScroll',function(){},false); 
		}
        window.onmousewheel=document.onmousewheel=function(){}
    });
	
	var showPop = function(ele){
        ele.show();
        setTimeout(function(){
            ele.addClass('show');
        },10);
        if(document.addEventListener){ 
			document.addEventListener('DOMMouseScroll',function(e){e.preventDefault(); return false;},false); 
		}
        window.onmousewheel=document.onmousewheel=function(){return false;}
    }
    
    var closePop = function(ele){
        ele.removeClass('show').hide();
    }
    
    var $popbg = $('#mask');
    var $dialog;
	
	//弹窗
	$(".step").click(function(){
		var index = $(this).index();
		$dialog = $("#Jdialog-"+index);
		$dialog.show();
		setTimeout(function(){
			$dialog.addClass("show");
		},50);
		showPop($popbg);
	});
	
	//滚动条
	$(".dialog-con").niceScroll({
		cursorborderradius: "7px",
		autohidemode: false,
		railpadding: {
			right: 10
		}
	});
});